﻿using System;
using System.Text;
using System.Data;
using System.Data.OleDb;
using System.Collections.Generic;
using System.Reflection;
namespace BLL
{
	 	//CMember
		public static class CMember
	{
        public static string LoginUserSessionKey = "UserL_rrb_xb_S_GG";

        public static string admin_SessionKey = "Admin_L_man6_age_KEY";
        /// <summary>
        /// 会员使用KEY
        /// </summary>
        public static string DESKey
        {
            get
            {//////"100-101-120-105-102-070-001-008"
                return "100-101-120-105-102-070-001-008";
            }
        }

        /// <summary>
        /// 后台管理员使用KEY
        /// </summary>
        public static string M_ADMIN_DESKey
        {
            get
            {//"190-201-320-205-302-170-101-101"
                return "190-201-320-205-302-170-101-101";
            }
        }
        /// <summary>
        /// 随机验证码长度
        /// </summary>
        public readonly static int rndLength = 6;
        public static string getRnd()
        {
            string ret = DateTime.Now.ToString("ssffffff");
            Random ran = new Random(unchecked((int)(DateTime.Now.Ticks)));
            int n1 = ran.Next(10000, 1000000000);
            n1 = ran.Next(n1);
            int n2 = ran.Next(10000, 1000000000);
            ret = n1.ToString() + ret + n2.ToString();
            if (ret == null || ret.Length < rndLength)
            {
                ret = ret + (ran.Next(1000, 1000000000)).ToString() + DateTime.Now.ToString("mmssffffff");
                if (ret == null || ret.Length < rndLength)
                {
                    ret = ret + (ran.Next(1000, 1000000000)).ToString() + DateTime.Now.ToString("mmssffffff");
                }
                if (ret == null || ret.Length < rndLength)
                {
                    ret = ret + (ran.Next(1000, 1000000000)).ToString() + DateTime.Now.ToString("mmssffffff");
                }
                if (ret == null || ret.Length < rndLength)
                {
                    ret = ret + (ran.Next(1000, 1000000000)).ToString() + DateTime.Now.ToString("mmssffffff");
                }
            }
            return ret.Substring(0, rndLength);
        }
	    private static Data.CMember Data_CMember = new Data.CMember();

        public static bool GetIsExitmob(string mob)
        {
            return Data_CMember.GetIsExitmob(mob);
        }
        public static bool GetIsExitNickname(string Nickname)
        {
            return Data_CMember.GetIsExitNickname(Nickname);
        }
        /// <summary>
        /// 获取登录用户信息
        /// </summary>
        /// <returns></returns>
        public static Model.CMember UserLoginInfo()
        {
            Model.CMember UserInfo = Session.Read<Model.CMember>(LoginUserSessionKey);
            //存在于Session
            if (UserInfo != null)
            {
                return UserInfo;
            }
            return null;
        }
        public static Model.CMember userLogin(string strusername,string password)
        {
            return Data_CMember.userLogin(strusername, password);
        }

        public static Model.Manageadmin ManageadminLoginInfo()
        {
            Model.Manageadmin admin = Session.Read<Model.Manageadmin>(admin_SessionKey);
            //存在于Session
            if (admin != null)
            {
                return admin;
            }
            return null;
        }
        public static Model.CMember GetOneBymob(string strmob)
        {
            return Data_CMember.GetOneBymob(strmob);
        }
        public static Model.CMember GetOneBynickname(string nickname)
        {
            return Data_CMember.GetOneBynickname(nickname);
        }
        public static string GetTheEmail(int Id)
        {
            return Data_CMember.GetTheEmail(Id);
        }
        public static List<Model.CMember> GetAllCmember_Canuse_Decode()
        {
            List<Model.CMember> ret = Data_CMember.GetAllCmember_Canuse();
            try
            {
                foreach (Model.CMember cm in ret)
                {
                    cm.u_password = BLL.Security.DES_Decode(cm.u_password, BLL.CMember.DESKey);
                }
            }
            catch { }
            return ret;
        }
        public static List<Model.CMember> GetAllCmember_Canuse_select()
        {
            List<Model.CMember> ret = Data_CMember.GetAllCmember_Canuse();           
            return ret;
        }
        public static List<Model.CMember> GetAllCmember_Canuse(long mob)
        {
            List<Model.CMember> ret = Data_CMember.GetAllCmember_Canuse(mob);
            try
            {
                foreach (Model.CMember cm in ret)
                {
                    cm.u_password = BLL.Security.DES_Decode(cm.u_password, BLL.CMember.DESKey);
                }
            }
            catch { }
            return ret;
        }

		/// <summary>
        /// 添加
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static long Add(Model.CMember model)
        {
              return Data_CMember.Add(model);
        }
         /// <summary>
        /// 修改
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static int Update(Model.CMember model)
        {
            return Data_CMember.Update(model);
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public static bool Delete(long Id)
        {
            return Data_CMember.Delete(Id);
        }       
        /// <summary>
        /// 单条
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public static Model.CMember GetModel(long Id)
        {
             return Data_CMember.GetModel(Id);
        }
        /// <summary>
        /// 总数据数
        /// </summary>
        /// <returns></returns>
        public static int GetAll_Count()
        {
            return Data_CMember.GetAll_Count();
        }
        public static int GetAll_Count_Canuse()
        {
            return Data_CMember.GetAll_Count_Canuse();
        }
        /// <summary>
        /// 抽取分页数据
        /// </summary>
        public static List<Model.CMember> Getall(int pageIndex, int pageSize,out int totalCount)
        {
            return Data_CMember.Getall(pageIndex, pageSize, out totalCount);
        }
        public static List<Model.CMember> GetPageList_Where(int pageIndex, int pageSize,string u_password,out int totalCount)
        {          
             return Data_CMember.GetPageList_Where(pageIndex, pageSize,u_password, out totalCount);
        }
        /// <summary>
        /// 批删
        /// </summary>
        /// <param name="Ids"></param>
        /// <returns></returns>
        public static int Drop(string Ids)
        {
            return Data_CMember.Drop(Ids);
        }
        public static bool GetIsExitemail(string email)
        {
            if (!string.IsNullOrEmpty(email) && !string.IsNullOrEmpty(email.Trim()))
            {
                StringBuilder sqlWhere = new StringBuilder();
                sqlWhere.Append("SELECT Id FROM [CMember] WHERE  [email]='");
                sqlWhere.Append(email.Trim());
                sqlWhere.Append("'");
                System.Data.DataTable DT = SpeciallySql.getDT_SpeciallySql(sqlWhere.ToString());
                if (DT != null && DT.Rows.Count > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return true;
            }
        } 
	}
}